package com.cwvs.cat.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cwvs.cat.ClubDetailActivity;
import com.cwvs.cat.R;
import com.cwvs.cat.bean.MyClub;
import com.cwvs.cat.bean.MyClubs;
import com.cwvs.cat.net.Port;

public class MyClubAdapter extends BaseAdapter {

	private Context mContext;
	private LayoutInflater mInflater = null;
	private ViewHolder holder = null;
	private List<MyClubs> mList;
	private FinalBitmap fb;
	public MyClubAdapter(Context context, List<MyClubs> list){
		this.mContext=context;
		this.mInflater = LayoutInflater.from(context);
		mList = list;
		fb = FinalBitmap.create(mContext);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_list_my_club, parent ,false);
			holder = new ViewHolder();
			holder.club_name = (TextView) convertView.findViewById(R.id.txt_club_name);
			holder.club_introduce = (TextView) convertView.findViewById(R.id.txt_club_introduce);
			holder.club_time = (TextView) convertView.findViewById(R.id.txt_club_time);
			holder.head_image = (ImageView) convertView.findViewById(R.id.head_image);
			holder.maoyou = (TextView) convertView.findViewById(R.id.maoyou);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.club_name.setText(mList.get(position).name);
		holder.club_introduce.setText(mList.get(position).introduce);
		holder.club_time.setText(mList.get(position).created);	
		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent=new Intent();
				intent.setClass(mContext, ClubDetailActivity.class);
				intent.putExtra("org_id", mList.get(position).id);
				intent.putExtra("my", "my");
				mContext.startActivity(intent);
			}
		});
		
		if (!mList.get(position).background_pic.equals("")&&!mList.get(position).background_pic.equals("null")) {
			if (mList.get(position).background_pic.contains("http")) {
				fb.display(holder.head_image,mList.get(position).background_pic);
			}else {
				fb.display(holder.head_image,Port.getImg+mList.get(position).background_pic);
			}
		}
		holder.maoyou.setText(mList.get(position).count);
		return convertView;
	}

	static class ViewHolder{
		public TextView club_name,club_introduce,club_time,maoyou;
		public ImageView head_image;
	}

}
